/**
 * Created by zhourb on 2017/12/17.
 */
var $ = require('jquery');
require('easyui');
require('fancybox');
var $alert = require('libs/alert');
$(function () {
    //获取url参数
    var id = $.getUrlParam("id");
    var status = {
        Y: '有效',
        N: '无效'
    };
    var recharge = {
        Y: '是',
        N: '否'
    };
    fillData(id);
    function fillData(id) {
        $.get('api/v1/p/mms/promotion/load',{id: id},function (res) {
            if(res.code == 200){
                var data = res.data,

                $firstTarget = $("#baseInfo").find("span");
                //元素赋值
                $firstTarget.eq(0).text(data.code);
                $firstTarget.eq(1).text(data.name);
                $firstTarget.eq(2).text(data.phone);
                $firstTarget.eq(3).text(data.mail);
                $firstTarget.eq(4).text(data.address);
                $firstTarget.eq(5).text(data.userName);
                $firstTarget.eq(6).text(data.url);
                $firstTarget.eq(7).text(data.createdDt);
                var sts = status[data.sts];
                $firstTarget.eq(8).text(sts);
                $firstTarget.eq(9).text(data.nums);
                $firstTarget.eq(10).text(data.remark);
                tableInit(data.code);
            }else{
                $alert(res.message);
            }
        });
    }
    function tableInit(code) {
        $("#mainTable").datagrid({
            url:'api/v1/p/mms/promotion/registerlist',
            border: false,
            pagination: true,
            pageSize: 10,
            pageList: [10, 20, 50, 100],
            singleSelect: true,
            rownumbers: true,
            emptyMsg: '暂无数据',
            queryParams: {
                code: code
            },
            columns:[[
                {
                    field : 'userName',
                    title : '注册账号',
                    width : '25%'
                },{
                    field : 'createdDt',
                    title : '注册时间',
                    width : '25%'
                },{
                    field : 'entName',
                    title : '客户名称',
                    width : '25%'
                },{
                    field : 'recharge',
                    title : '是否充值',
                    width : '25%',
                    formatter: function(value,row,index){
                        return recharge[value];
                    }
                }
                ]],
            onClickRow: function (rowIndex, rowData) {
                $(this).datagrid('unselectRow', rowIndex);
            },
            loadFilter:function(data){
                if(data.code == '200'){
                    return data.data;
                }else{
                    return [];
                }
            }
        });
    }
});
